<template>
  <div id="aCoursesList" class="bg-fa of">
    <!-- /课程列表 开始 -->
    <section class="container">
      <header class="comm-title">
        <h2 class="fl tac">
          <span class="c-333">全部产品</span>
        </h2>
      </header>
      <section class="c-sort-box">
        <section class="c-s-dl">
          <dl>
            <dt>
              <span class="c-999 fsize14">分类</span>
            </dt>
            <dd class="c-s-dl-li">
              <ul class="clearfix">
                <li ref="now" @click="classifyQuery(2)" class="current">
                  <a title="秒杀中" href="javascript:;">秒杀中</a>
                </li>
                <li ref="future" @click="classifyQuery(3)">
                  <a title="未开始" href="javascript:;">未开始</a>
                </li>
                <li ref="over" @click="classifyQuery(4)">
                  <a title="已过期" href="javascript:;">已结束</a>
                </li>
              </ul>
            </dd>
          </dl>
          <div class="clear"></div>
        </section>
        <br />
        <div class="js-wrap">
          <section class="fr">
            <span class="c-ccc">
              <i class="c-master f-fM">1</i>/
              <i class="c-666 f-fM">1</i>
            </span>
          </section>
          <section class="fl">
            <ol class="js-tap clearfix">
              <li class="current bg-orange">
                <a title="时间" href="#">时间&nbsp; ↓</a>
              </li>
            </ol>
          </section>
        </div>
        <div class="mt40">
          <!-- /无数据提示 开始-->
          <section v-if="productList.length <= 0" class="no-data-wrap">
            <em class="icon30 no-data-ico">&nbsp;</em>
            <span class="c-666 fsize14 ml10 vam"
              >没有相关数据，工作人员正在努力发布中...</span
            >
          </section>
          <!-- /无数据提示 结束-->
          <article v-if="productList.length > 0" class="comm-course-list">
            <ul class="of" id="bna">
              <li v-for="itme in productList" :key="itme.id">
                <div class="cc-l-wrap">
                  <section class="course-img">
                    <img
                      :src="itme.img"
                      style="width: 100%; height: 150px"
                      class="img-responsive"
                    />
                    <div class="cc-mask">
                      <a
                        :href="'/seckillProduct/' + itme.id"
                        title="查看详情"
                        class="comm-btn c-btn-1"
                        >查看详情</a
                      >
                    </div>
                  </section>
                  <h3 class="hLh30 txtOf mt10">
                    <a
                      :href="'/product/' + itme.id"
                      :title="itme.name"
                      class="course-title fsize18 c-333"
                      >{{ itme.name }}</a
                    >
                  </h3>
                  <section class="mt10 hLh20 of">
                    <span class="fr jgTag bg-green">
                      <i style="cursor: pointer" class="c-fff fsize12 f-fA"
                        >￥{{ itme.price }}</i
                      >
                    </span>
                    <span class="fl jgAttr c-ccc f-fA">
                      <i class="c-999 f-fA">{{ itme.sale }}人已购买</i>
                      |
                      <i v-if="index == 2" class="c-999 f-fA">秒杀中</i>
                      <i v-if="index == 3" class="c-999 f-fA">未开始</i>
                      <i v-if="index == 4" class="c-999 f-fA">已结束</i>
                    </span>
                  </section>
                </div>
              </li>
            </ul>
            <div class="clear"></div>
          </article>
        </div>
        <!-- 公共分页 开始 -->
        <el-pagination
          v-if="productList.length > 0"
          background
          layout="prev, pager, next"
          @current-change="page"
          :current-page="queryInfo.pagenum"
          :page-size="queryInfo.pagesize"
          :total="total"
          style="text-align: center"
        >
        </el-pagination>
        <!-- 公共分页 结束 -->
      </section>
    </section>
    <!-- /课程列表 结束 -->
  </div>
</template>
<script>
import SeckillProductApi from "@/api/seckillProduct.js";
export default {
  data() {
    return {
      index: 2,
      property: "value",
      productList: [],
      otal: 0,
      queryInfo: {
        query: "",
        // 当前页数
        pagenum: 1,
        // 显示一页多少条数据
        pagesize: 8,
      },
    };
  },
  methods: {
    page(newsize) {
      switch (this.index) {
        case 2:
          this.getNowSeckillProduct(newsize);
        case 3:
          this.getBeforeSeckillProduct(newsize);
        case 4:
          this.getAfterSeckillProduct(newsize);
      }
    },
    getNowSeckillProduct(pagenum) {
      SeckillProductApi.getSeckillProdctByNow(pagenum).then((response) => {
        if (response.data.code == 200) {
          if (response.data.data.data != null) {
            this.productList = response.data.data.data;
            this.total = response.data.data.total;
          } else {
            this.productList = [];
            this.total = 0;
          }
        } else {
          this.$message.error(response.data.msg);
        }
      });
    },
    getBeforeSeckillProduct(pagenum) {
      SeckillProductApi.getSeckillProdctByBefore(pagenum).then((response) => {
        if (response.data.code == 200) {
          if (response.data.data.data != null) {
            this.productList = response.data.data.data;
            this.total = response.data.data.total;
          } else {
            this.productList = [];
            this.total = 0;
          }
        } else {
          this.$message.error(response.data.msg);
        }
      });
    },
    getAfterSeckillProduct(pagenum) {
      SeckillProductApi.getSeckillProdctByAfter(pagenum).then((response) => {
        if (response.data.code == 200) {
          if (response.data.data.data != null) {
            this.productList = response.data.data.data;
            this.total = response.data.data.total;
          } else {
            this.productList = [];
            this.total = 0;
          }
        } else {
          this.$message.error(response.data.msg);
        }
      });
    },
    classifyQuery(index) {
      if (index == this.index) {
        return;
      }
      switch (index) {
        case 2:
          //代码块；
          this.index = index;
          this.$refs.now.className = "current";
          this.$refs.future.className = "";
          this.$refs.over.className = "";
          this.getNowSeckillProduct(1);
          break;
        case 3:
          //代码块；
          this.index = index;
          this.$refs.now.className = "";
          this.$refs.future.className = "current";
          this.$refs.over.className = "";
          this.getBeforeSeckillProduct(1);
          break;
        case 4:
          //代码块；
          this.index = index;
          this.$refs.now.className = "";
          this.$refs.future.className = "";
          this.$refs.over.className = "current";
          this.getAfterSeckillProduct(1);
          break;
      }
    },
  },
  created() {
    this.getNowSeckillProduct(1);
  },
};
</script>